package com.ruoyi.pingan.fymodule.order.service.impl;


import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.pingan.config.PayConfig;
import com.ruoyi.pingan.fymodule.account.entity.SxoSafetyUser;
import com.ruoyi.pingan.fymodule.account.enums.CodeEnum;
import com.ruoyi.pingan.fymodule.account.enums.SourceEnum;
import com.ruoyi.pingan.fymodule.account.service.ISxoSafetyUserService;
import com.ruoyi.pingan.fymodule.account.util.CommonUtil;
import com.ruoyi.pingan.fymodule.account.util.PaPayUtil;
import com.ruoyi.pingan.fymodule.account.util.TradetraceUtil;
import com.ruoyi.pingan.fymodule.exception.BusinessException;
import com.ruoyi.pingan.fymodule.goodsinfo.goods.api.SxoGoodsApi;
import com.ruoyi.pingan.fymodule.goodsinfo.goods.api.SxoGoodsCategoryApi;
import com.ruoyi.pingan.fymodule.goodsinfo.goods.service.SxoGoodsService;
import com.ruoyi.pingan.fymodule.goodsinfo.goods.vo.SxoGoodsApiVo;
import com.ruoyi.pingan.fymodule.goodsinfo.goods.vo.SxoGoodsCategoryApiVo;
import com.ruoyi.pingan.fymodule.goodsinfo.goods.vo.SxoGoodsCategoryJoinApi;
import com.ruoyi.pingan.fymodule.order.entity.*;
import com.ruoyi.pingan.fymodule.order.mapper.SxoSafetyShopOrderMapper;
import com.ruoyi.pingan.fymodule.order.model.dto.CalculateOrderDto;
import com.ruoyi.pingan.fymodule.order.model.dto.SxoSafetyShopOrderDto;
import com.ruoyi.pingan.fymodule.order.service.*;
import com.ruoyi.pingan.fymodule.plugins.entity.SxoPluginsShop;
import com.ruoyi.pingan.fymodule.plugins.service.ISxoPluginsShopService;

import com.ruoyi.pingan.fymodule.separateSetting.categorytemplate.entity.FywCategoryTemplate;
import com.ruoyi.pingan.fymodule.separateSetting.categorytemplate.service.FywCategoryTemplateService;
import com.ruoyi.pingan.fymodule.separateSetting.storesetting.entity.FywGoodsCategory;
import com.ruoyi.pingan.fymodule.separateSetting.storesetting.entity.FywStoreSetting;
import com.ruoyi.pingan.fymodule.separateSetting.storesetting.service.FywGoodsCategoryService;
import com.ruoyi.pingan.fymodule.separateSetting.storesetting.service.FywStoreSettingService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 平安分账店铺订单 业务层实现
 *
 * @author wangy
 * @since 2025-08-04
 */
@Slf4j
@Service
public class SxoSafetyShopOrderServiceImpl extends ServiceImpl<SxoSafetyShopOrderMapper, SxoSafetyShopOrder> implements ISxoSafetyShopOrderService {

    @Autowired
    private FywGoodsCategoryService fywGoodsCategoryService;
    @Autowired
    private FywStoreSettingService fywStoreSettingService;

    @Autowired
    private FywCategoryTemplateService fywCategoryTemplateService;
    @Autowired
    private PayConfig payConfig;
    @Autowired
    private ISxoOrderService sxoOrderService;
    @Autowired
    private ISxoOrderDetailService sxoOrderDetailService;
    @Autowired
    private ISxoSafetyOrderService sxoSafetyOrderService;
    @Autowired
    private ISxoSafetyOrderDetailService sxoSafetyOrderDetailService;
    @Autowired
    private ISxoSafetyUserService sxoSafetyUserService;
    @Autowired
    private ISxoPayRequestLogService sxoPayRequestLogService;
    @Autowired
    private ISxoPayLogValueService sxoPayLogValueService;
    @Autowired
    private ISxoPayLogService sxoPayLogService;
    @Autowired
    private SxoGoodsCategoryApi sxoGoodsCategoryApi;
    @Autowired
    private SxoGoodsApi sxoGoodsApi;
    @Autowired
    private ISxoPluginsShopService sxoPluginsShopService;
    @Autowired
    private SxoGoodsService sxoGoodsService;


    @Override
    public void taskSafetyShopOrder(SxoSafetyShopOrderDto dto) {
        log.info("定时任务开始执行:{}", JSON.toJSONString(dto));
        LambdaQueryWrapper<SxoSafetyShopOrder> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SxoSafetyShopOrder::getLiquidationApiStatus, dto.getLiquidationApiStatus());
        wrapper.eq(SxoSafetyShopOrder::getLiquidationStatus, dto.getLiquidationStatus());
        wrapper.eq(SxoSafetyShopOrder::getStatus, "0");
        wrapper.ge(SxoSafetyShopOrder::getLiquidationApiTime, dto.getStartTime());
        wrapper.le(SxoSafetyShopOrder::getLiquidationApiTime, dto.getEndTime());
        List<SxoSafetyShopOrder> list = list(wrapper);
        if (list.isEmpty()) {
            return;
        }
        List<SxoSafetyShopOrder> shopOrders = new ArrayList<>();
        String data = DateUtil.now();
        for (SxoSafetyShopOrder order : list) {
            SxoSafetyShopOrder o = new SxoSafetyShopOrder();
            o.setId(order.getId());
            o.setLiquidationStatus(1);
            try {
                CalculateOrderDto calculateOrderDto = new CalculateOrderDto();
                calculateOrderDto.setId(order.getOrderId());
                calculateOrder(calculateOrderDto);
                o.setLiquidationSucTime(data);
                o.setLiquidationUpdTime(data);
                if (StrUtil.isNotEmpty(order.getErrorMsg())) {
                    o.setErrorMsg("");
                }
            } catch (Exception e) {
                o.setLiquidationUpdTime(data);
                o.setLiquidationStatus(-1);
                o.setErrorMsg(e.getMessage());
                log.error("订单{}处理异常：{}", order.getOrderId(), e.getMessage());
            }
            shopOrders.add(o);
        }
        if (!shopOrders.isEmpty()) {
            this.updateBatchById(shopOrders);
        }
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void   calculateOrder(CalculateOrderDto dto) {
        log.info("订单{}开始处理;时间：{}", dto.getId(), DateUtil.now());
        LambdaQueryWrapper<SxoSafetyOrder> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SxoSafetyOrder::getOrderId, dto.getId());
        queryWrapper.in(SxoSafetyOrder::getOrdersStatus, "0", "2", "1");
        queryWrapper.eq(SxoSafetyOrder::getStatus, "0");
        long count = sxoSafetyOrderService.count(queryWrapper);
//        if (count > 0) {
//            throw new BusinessException(CodeEnum.SERVER_ERROR.getCode(), "当前订单已存在冻结充值；无法重复推送");
//        }

        LambdaQueryWrapper<SxoOrder> orderWrapper = new LambdaQueryWrapper<>();
        orderWrapper.eq(SxoOrder::getId, dto.getId());
        orderWrapper.and(o->o.eq(SxoOrder::getStatus, "2").or().eq(SxoOrder::getStatus, "3").or().eq(SxoOrder::getStatus, "7"));
        List<SxoOrder> sxoOrders = sxoOrderService.list(orderWrapper);
        if (sxoOrders.isEmpty()) {
            throw new BusinessException(CodeEnum.SERVER_ERROR.getCode(), "订单ID错误");
        }
        SxoOrder sxoOrder = sxoOrders.get(0);
        if (!sxoOrder.getPayStatus().equals(1)) {
            throw new BusinessException(CodeEnum.SERVER_ERROR.getCode(), "当前订单未支付或者已退款，无法进行冻结充值");
        }
        List<SxoOrderDetail> orderDetails = sxoOrderDetailService.listOrderDetailByOrderId(sxoOrder.getId());
        if (orderDetails.isEmpty()) {
            throw new BusinessException(CodeEnum.SERVER_ERROR.getCode(), "未找到订单明细");
        }

//        //商品信息
//        List<String> goodsIds = orderDetails.stream().map(SxoOrderDetail::getGoodsId).toList();
//        List<SxoGoodsApiVo> goodsList = sxoGoodsApi.listGoods(goodsIds);
//        List<SxoGoodsCategoryJoinApi> categoryJoinList = sxoGoodsCategoryApi.listGoodsCategoryJoin(goodsIds);
//        if (categoryJoinList.isEmpty()){
//            throw new BusinessException(CodeEnum.SERVER_ERROR.getCode(), "未找到商品未设置分类");
//        }
//        List<String> categoryIds = categoryJoinList.stream().map(SxoGoodsCategoryJoinApi::getCategoryId).toList();
//        List<SxoGoodsCategoryApiVo> categoryList = sxoGoodsCategoryApi.listTopGoodsCategory(categoryIds);
//        if (categoryList.isEmpty()){
//            throw new BusinessException(CodeEnum.SERVER_ERROR.getCode(), "未找到商品分类");
//        }
        String totalOrderNo = dto.getChannelOrderNo();
        if (StrUtil.isEmpty(totalOrderNo)) {
            LambdaQueryWrapper<SxoPayLogValue> wqLv = new LambdaQueryWrapper<>();
            wqLv.eq(SxoPayLogValue::getBusinessId, sxoOrder.getId());
            List<SxoPayLogValue> sxoPayLogValues = sxoPayLogValueService.list(wqLv);
            if (sxoPayLogValues.isEmpty()) {
                throw new BusinessException(CodeEnum.SERVER_ERROR.getCode(), "订单logValue无数据");
            }
            SxoPayLogValue sxoPayLogValue = sxoPayLogValues.get(0);
            SxoPayLog payLog = sxoPayLogService.getById(sxoPayLogValue.getPayLogId());
            if (payLog == null) {
                throw new BusinessException(CodeEnum.SERVER_ERROR.getCode(), "订单paylog无数据");
            }

            LambdaQueryWrapper<SxoPayRequestLog> wqRl = new LambdaQueryWrapper<>();
            wqRl.eq(SxoPayRequestLog::getTradeNo, payLog.getTradeNo());
            List<SxoPayRequestLog> payRequestLogs = sxoPayRequestLogService.list(wqRl);
            if (payRequestLogs.isEmpty()) {
                throw new BusinessException(CodeEnum.SERVER_ERROR.getCode(), "订单PayRequestLog无数据");
            }
            SxoPayRequestLog sxoPayRequestLog = payRequestLogs.get(0);
            String requestParams = sxoPayRequestLog.getRequestParams();
            if (StrUtil.isEmpty(sxoPayRequestLog.getRequestParams())) {
                throw new BusinessException(CodeEnum.SERVER_ERROR.getCode(), "订单RequestParams无数据");
            }
            Map<String, String> map = buildOrderReq(requestParams);
            totalOrderNo = map.get(PaPayUtil.CHANNEL_ORDER_NO);
            if (StrUtil.isEmpty(totalOrderNo)) {
                totalOrderNo = payLog.getTradeNo();
                if (StrUtil.isEmpty(totalOrderNo)) {
                    throw new BusinessException(CodeEnum.SERVER_ERROR.getCode(), "订单ChannelOrderNo无数据");
                }
            }
        }

        LambdaQueryWrapper<SxoPluginsShop> sxoPluginsShopWrapper = new LambdaQueryWrapper<>();
        sxoPluginsShopWrapper.eq(SxoPluginsShop::getId, sxoOrder.getShopId());
        SxoPluginsShop sxoPluginsShop = sxoPluginsShopService.getOne(sxoPluginsShopWrapper);

        SxoSafetyUser safetyUser = sxoSafetyUserService.findUser(sxoPluginsShop.getUserId(), SourceEnum.SHOP.getCode());
        if (safetyUser == null) {
            throw new BusinessException(CodeEnum.SERVER_ERROR.getCode(), "当前商家未认证");
        }

        //商家分账比例
        LambdaQueryWrapper<FywStoreSetting> storeSettingWrapper = new LambdaQueryWrapper<>();
        storeSettingWrapper.eq(FywStoreSetting::getStoreId, sxoOrder.getShopId());
        List<FywStoreSetting> storeSettings = fywStoreSettingService.list(storeSettingWrapper);
        if (storeSettings.isEmpty()) {
            throw new BusinessException(CodeEnum.SERVER_ERROR.getCode(), "未找到商家分账比例信息");
        }
        FywStoreSetting storeSetting = storeSettings.get(0);
        FywCategoryTemplate fywCategoryTemplate = fywCategoryTemplateService.getById(storeSetting.getCategoryId());
        if (fywCategoryTemplate == null) {
            throw new BusinessException(CodeEnum.SERVER_ERROR.getCode(), "未找到商家分账比例模版信息");
        }
        LambdaQueryWrapper<FywGoodsCategory> categoryWrapper = new LambdaQueryWrapper<>();
        categoryWrapper.eq(FywGoodsCategory::getCategoryId, fywCategoryTemplate.getCategoryId());
        List<FywGoodsCategory> goodsCategories = fywGoodsCategoryService.list(categoryWrapper);
        if (goodsCategories.isEmpty()) {
            throw new BusinessException(CodeEnum.SERVER_ERROR.getCode(), "未找到商家分账比例模版值信息");
        }
        FywGoodsCategory fywGoodsCategory = goodsCategories.get(0);

        int scale = 2;
        BigDecimal paR = new BigDecimal("0.22");
        BigDecimal paRation = NumberUtil.div(paR, 100, scale);

        BigDecimal totalAcctAmt = new BigDecimal("0.00");
        BigDecimal totalSerAcctAmt = new BigDecimal("0.00");
        BigDecimal totalSerAcctPaAmt = new BigDecimal("0.00");
        BigDecimal rationShop =  new BigDecimal("0");

        List<SxoSafetyOrderDetail> details = new ArrayList<>();
        for (SxoOrderDetail orderDetail : orderDetails) {

            //商品信息
            List<String> goodsIds = orderDetails.stream().map(SxoOrderDetail::getGoodsId).toList();
            SxoGoodsApiVo goodsList = sxoGoodsApi.findGoods(orderDetail.getGoodsId());
            SxoGoodsCategoryJoinApi categoryJoin = sxoGoodsCategoryApi.findGoodsCategoryJoin(orderDetail.getGoodsId());
            if (categoryJoin==null){
                throw new BusinessException(CodeEnum.SERVER_ERROR.getCode(), "未找到商品未设置分类");
            }
            List<String> a = new ArrayList<>();
            String categoryIds = categoryJoin.getCategoryId();
            a.add(categoryIds);
            List<SxoGoodsCategoryApiVo> categoryList = sxoGoodsCategoryApi.listTopGoodsCategory(a);

            if (categoryList.isEmpty()){
                throw new BusinessException(CodeEnum.SERVER_ERROR.getCode(), "未找到商品分类");
            }
//            int a = 1;
//            SxoGoodsApiVo goods = goodsList.stream().filter(o -> o.getId().equals(orderDetail.getGoodsId())).findFirst().orElse(null);
//            if (goods == null) {
//                continue;
//            }
//            SxoGoodsCategoryJoinApi categoryJoin = categoryJoinList.stream().filter(o -> o.getGoodsId().equals(orderDetail.getGoodsId())).findFirst().orElse(null);
//            if (categoryJoin == null) {
//                continue;
//            }
//            SxoGoodsCategoryApiVo category = categoryList.stream().filter(o -> o.getId().equals(categoryJoin.getCategoryId())).findFirst().orElse(null);
//            if (category == null) {
//                continue;
//            }
            SxoGoodsCategoryApiVo category = categoryList.get(0);
//            BigDecimal totalPrice = orderDetail.getCoupon() != null ? NumberUtil.sub(orderDetail.getTotalPrice().toString(),orderDetail.getCoupon().toString()) : orderDetail.getTotalPrice();
            BigDecimal totalPrice = orderDetail.getTotalPrice();

            //商家
            BigDecimal shopR = getRatio(category, fywGoodsCategory);

            log.info("shopR: "+shopR);
            BigDecimal shopRation = NumberUtil.div(shopR, 100, scale);
            log.info("shopRation: "+shopRation);

            BigDecimal shopPrice = NumberUtil.mul(totalPrice, shopRation).setScale(scale, RoundingMode.HALF_UP);
            log.info("shopPrice: "+shopPrice);
            rationShop = shopR;
            //平安=(总金额-商家）*平安比例
            BigDecimal selefPaPrice = NumberUtil.sub(totalPrice, shopPrice);
            log.info("selefPaPrice: "+selefPaPrice);

            BigDecimal paPrice = NumberUtil.mul(selefPaPrice, paRation).setScale(scale, RoundingMode.HALF_UP);
            log.info("paPrice: "+paPrice);

            //平台=总金额-商家-平安
            BigDecimal selefPrice = NumberUtil.sub(selefPaPrice, paPrice);
            log.info("selefPrice: "+selefPrice);


            SxoSafetyOrderDetail detail = new SxoSafetyOrderDetail();
            detail.setGoodsId(orderDetail.getGoodsId());
            //这个子账号应该不是同一个，先通过商品id查询店铺id，再通过店铺id查询userid，再通过userid查询供应商子账号
//
//            LambdaQueryWrapper<SxoGoods> goodsWrapper = new LambdaQueryWrapper<>();
//            goodsWrapper.eq(SxoGoods::getId, sxoOrder.getShopId());
//            List<SxoGoods> goodsSettings = sxoGoodsService.list(goodsWrapper);
//            if (goodsSettings.isEmpty()) {
//                throw new BusinessException(CodeEnum.SERVER_ERROR.getCode(), "未找到药品信息");
//            }

            LambdaQueryWrapper<SxoPluginsShop>  ShopWrapper = new LambdaQueryWrapper<>();
            ShopWrapper.eq(SxoPluginsShop::getId, sxoOrder.getShopId());
            SxoPluginsShop PluginsShop = sxoPluginsShopService.getOne(ShopWrapper);

            SxoSafetyUser gysUser = sxoSafetyUserService.findUser(PluginsShop.getUserId(), SourceEnum.SHOP.getCode());


            detail.setSubOrderFillSubAcctNo(gysUser.getSubAcctNo());
            detail.setSubOrderFillAmt(totalPrice.toString());
            detail.setAcctAmt(shopPrice.toString());
            detail.setSerAcctPaAmt(paPrice.toString());
            detail.setSerAcctAmt(selefPrice.toString());
            detail.setSubOrderFillCommission("0");
            detail.setSubFillOrderNo(TradetraceUtil.buildTradetracePay());
            detail.setSubOrderFillDesc("");
            detail.setSubOrderFillRemark("");
            detail.setRationId(storeSetting.getCategoryId());
            detail.setRationName(storeSetting.getCategoryName());
            detail.setRationShop(shopR.toString());
            detail.setRationPa(paR.toString());
            if (orderDetail.getCoupon() != null) {
                detail.setCoupon(orderDetail.getCoupon().toString());
            }
            details.add(detail);



            totalAcctAmt = NumberUtil.add(shopPrice, totalAcctAmt);
            log.info("分账总金额添加商品价格金额："+totalAcctAmt);
            totalSerAcctAmt = NumberUtil.add(selefPrice, totalSerAcctAmt);
            totalSerAcctPaAmt = NumberUtil.add(paPrice, totalSerAcctPaAmt);


        }

        BigDecimal tranTotalAmt = NumberUtil.sub(sxoOrder.getPayPrice().toString(),sxoOrder.getIncreasePrice().toString());
        String payChannelType = "0040";
        String merNo = payConfig.getMerNo();
        //订单信息
        String payOrderDate = CommonUtil.getYyyyMMdd(sxoOrder.getPayTime());
        if (payConfig.getTest() != null && payConfig.getTest()) {
            String st = String.valueOf(DateUtil.current() / 1000);
            payOrderDate = CommonUtil.getYyyyMMdd(st);
        }
        SxoPluginsShop pluginsShop = sxoPluginsShopService.getById(sxoOrder.getShopId());
        SxoSafetyOrder safetyOrder = new SxoSafetyOrder();
        String data = DateUtil.now();
        safetyOrder.setUserId(sxoOrder.getUserId());
        safetyOrder.setOrderId(sxoOrder.getId());
        safetyOrder.setOrderNo(sxoOrder.getOrderNo());
        safetyOrder.setShopId(sxoOrder.getShopId());
        if (pluginsShop != null) {
            safetyOrder.setShopName(pluginsShop.getName());
        }
        safetyOrder.setTranNetMemberCode(safetyUser.getTranNetMemberCode());
        safetyOrder.setPayChannelType(payChannelType);
        safetyOrder.setPayChannelAssignMerNo(merNo);
        safetyOrder.setPayOrderDate(payOrderDate);
        safetyOrder.setOrderMonth(CommonUtil.getYyyyMM(sxoOrder.getAddTime()));
        safetyOrder.setTotalOrderNo(totalOrderNo);
        safetyOrder.setPayTime(CommonUtil.getTime(sxoOrder.getPayTime()));
        safetyOrder.setOrderTotalAmt(sxoOrder.getTotalPrice().toString());
        safetyOrder.setIncreasePrice(sxoOrder.getIncreasePrice().toString());
        safetyOrder.setTranTotalAmt(tranTotalAmt.toString());
        safetyOrder.setTotalAcctAmt(totalAcctAmt.toString());
        safetyOrder.setPlatTotalAmt(sxoOrder.getPlatPreferentialPrice().toString());
        safetyOrder.setTotalSerAcctAmt(totalSerAcctAmt.toString());
        safetyOrder.setTotalSerAcctPaAmt(totalSerAcctPaAmt.toString());
        safetyOrder.setOrdersCount("1");
        safetyOrder.setOrdersStatus(1);
        safetyOrder.setStatus(0);
        safetyOrder.setAddTime(data);
        safetyOrder.setUpdTime(data);
        if (!details.isEmpty()) {
            sxoSafetyOrderService.save(safetyOrder);
            for (SxoSafetyOrderDetail detail : details) {
                detail.setSafetyOrderId(safetyOrder.getId());
            }
            sxoSafetyOrderDetailService.saveBatch(details);
        }
        log.info("订单{}结束处理;时间：{}", dto.getId(), DateUtil.now());
    }



   /* public static void main(String[] args) {
        int scale = 2;
        BigDecimal totalPrice = new BigDecimal("15.79");
        BigDecimal paR = new BigDecimal("0.22");
        BigDecimal paRation = NumberUtil.div(paR,100,scale);
        System.out.println(paRation);

        BigDecimal shopR = new BigDecimal("97");
        BigDecimal shopRation = NumberUtil.div(shopR,100,scale);
        System.out.println(shopRation);
        BigDecimal shopPrice = NumberUtil.mul(totalPrice,shopRation).setScale(scale,RoundingMode.HALF_UP);
        System.out.println("商家："+shopPrice);

        //平台+平安=总金额-商家
        BigDecimal selefPaPrice = NumberUtil.sub(totalPrice,shopPrice);
        System.out.println("平台+平安："+selefPaPrice);
        BigDecimal paPrice = NumberUtil.mul(selefPaPrice,paRation).setScale(scale,RoundingMode.HALF_UP);
        System.out.println("平安："+paPrice);

        BigDecimal selefPrice = NumberUtil.sub(selefPaPrice,paPrice);
        System.out.println("平台："+selefPrice);
    }*/

    private BigDecimal getRatio(SxoGoodsCategoryApiVo category, FywGoodsCategory fywGoodsCategory) {
        String categoryName = category.getName();
        if (categoryName.equals("药品")) {
            return fywGoodsCategory.getYpSettleRate();
        }
        if (categoryName.equals("食品")) {
            return fywGoodsCategory.getSpSettleRate();
        }
        if (categoryName.equals("医疗器械")) {
            return fywGoodsCategory.getYlqxSettleRate();
        }
        if (categoryName.equals("日用品")) {
            return fywGoodsCategory.getRypSettleRate();
        }
        if (categoryName.equals("化妆品")) {
            return fywGoodsCategory.getHzpSettleRate();
        }
        if (categoryName.equals("保健用品")) {
            return fywGoodsCategory.getBjypSettleRate();
        }
        if (categoryName.equals("中药饮片")) {
            return fywGoodsCategory.getZyypSettleRate();
        }
        return BigDecimal.valueOf(97.00);
    }

    private Map<String, String> buildOrderReq(String requestParams) {
        Map<String, String> map = new HashMap<>();
        String[] arry = requestParams.split("&");
        for (int i = 0; i < arry.length; i++) {
            String[] arr = arry[i].split("=");
            if (arr.length == 2) {
                map.put(arr[0], arr[1]);
            } else {
                map.put(arr[0], "");
            }
        }
        return map;
    }
}